﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Formatting;
using System.Web;
using System.Web.Http.Filters;
using TjZheng.Framework;

namespace TjZheng.WebApi.Test.Controllers
{
    public class MyExceptionFilter : ExceptionFilterAttribute
    {
        public override void OnException(HttpActionExecutedContext actionExecutedContext)
        {
            //actionExecutedContext.Response = actionExecutedContext.Request.CreateResponse<InvokeResult>(System.Net.HttpStatusCode.OK, new InvokeResult { ResultCode = "Error", ResultMessage = "对不起，服务器开小差了" }, new XmlMediaTypeFormatter { UseXmlSerializer = true });

            //actionExecutedContext.Response = actionExecutedContext.Request.CreateResponse<InvokeResult>(System.Net.HttpStatusCode.OK, new InvokeResult { ResultCode = "Error", ResultMessage = "对不起，服务器开小差了" }, new JsonMediaTypeFormatter { UseDataContractJsonSerializer = true });         

            actionExecutedContext.Response = actionExecutedContext.Request.CreateResponse<InvokeResult>(System.Net.HttpStatusCode.OK, new InvokeResult { ResultCode = "Error", ResultMessage = "对不起，服务器开小差了" }, new JavascriptMediaTypeFormatter());

            //actionExecutedContext.Response.Content = new ObjectContent<InvokeResult>(new InvokeResult { ResultCode = "Error", ResultMessage = "对不起，服务器开小差了" }, new JsonMediaTypeFormatter());
            //actionExecutedContext.Response = actionExecutedContext.ActionContext.ActionDescriptor.ResultConverter.Convert(actionExecutedContext.ActionContext.ControllerContext, new List<string> { actionExecutedContext.Exception.StackTrace });
            //记录日志
            //base.OnException(actionExecutedContext);
        }
    }
}